'''
https://leetcode.cn/problems/minimum-operations-to-halve-array-sum/
'''
import heapq
from typing import List


class Solution:
    def halveArray(self, nums: List[int]) -> int:
        total = sum(nums)
        target = total / 2
        nums = list(map(lambda x: -x, nums))
        heapq.heapify(nums)

        t = 0
        while target > 0:
            v = heapq.heapreplace(nums, nums[0] / 2)
            target += v / 2
            t += 1
        return t


nums = [1, 2, 3, 4, 5]
r = Solution().halveArray(nums)
print(r)
